Skip to content

Backport #5503: [swc-plugin] Compile a "use step" function expression bound to a variable inside a function as a nested step - #5509

Merged
TooTallNate merged 1 commit into
stablefrom
backport/pr-5503-to-stable
Nov 17, 2026
Merged

TooTallNate merged 1 commit into
stablefrom
backport/pr-5503-to-stable

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Automated backport of #5503 to stable (backport job run).

AI recommendation: This fixes a bug in a feature stable already has. A "use step" function expression bound to a variable inside a workflow is compiled as a module-level step, so the run fails with "Step ... is not registered". The same un-scoped Expr::Fn branch in visit_mut_var_decl exists on stable, which already supports nested arrow steps and closure variables. The plugin code on stable has diverged from main (different helper signatures and a Client mode), so expect the cherry-pick to conflict and review it carefully.

Merge conflicts were resolved by AI (opencode with anthropic/claude-opus-5.5). Please review the conflict resolution carefully before merging.

…able inside a function as a nested step (#5503)

A `"use step"` function expression bound to a variable inside a workflow
(or any other function) was compiled as a module-level step, so the run
failed when it reached it:

```ts
export async function receiptWorkflow(n: number, label: string) {
  'use workflow';
  const send = async function () {
    'use step';
    return `${label}:${n}`;
  };
  return send(); // Step "step//./workflows/receipt//send" is not registered
}
```

The arrow form (`const send = async () => { 'use step'; ... }`) and a
function declaration already worked.

**Cause:** in `visit_mut_var_decl`, the `Expr::Fn` step branch had no
nested-scope check, unlike the `Expr::Arrow` branch next to it. As a
result:

- step mode emitted a registration for a binding that doesn't exist at
module scope, so nothing was registered;
- workflow mode called the un-namespaced step ID (`…//send`) without a
closure-variable getter.

**Fix:** inside a function, this branch now takes the same path as the
arrow form. The step is hoisted and namespaced by the enclosing function
(`receiptWorkflow/send`), it gets the variables it captures, and the
original function is kept with the directive stripped for direct calls.
A step bound to a variable takes the variable's name, as it already did
at module scope and for arrows. Module-level function expressions are
unchanged.

- **New fixture** (`nested-step-function-expression`): named and
anonymous function expressions inside a workflow, one inside a plain
helper function, and a module-level control. The step and workflow
outputs agree on every step ID, which `step_id_consistency` checks. All
421 Rust tests pass, and existing fixture outputs are unchanged.
- **Runtime:** the vitest workbench runs a workflow with a named and an
anonymous function-expression step, both capturing workflow variables.
On the previous plugin build it fails with `Step
"step//./workflows/nested-step-ids//named" is not registered`; with this
change it passes. The full vitest workbench passes (77 tests, plus one
marked as an expected failure).
- **Spec:** `spec.md` lists the nested-step forms and how each is named.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
Co-authored-by: Pranay Prakash <1797812+pranaygp@users.noreply.github.com>
Signed-off-by: Pranay Prakash <pranay.gp@gmail.com>
@changeset-bot

changeset-bot Bot commented Nov 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 37665b8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 17 packages
Name Type
@workflow/swc-plugin Patch
@workflow/astro Patch
@workflow/builders Patch
@workflow/cli Patch
@workflow/nest Patch
@workflow/next Patch
@workflow/nitro Patch
@workflow/rollup Patch
@workflow/sveltekit Patch
workflow Patch
@workflow/vite Patch
@workflow/vitest Patch
@workflow/world-testing Patch
@workflow/nuxt Patch
@workflow/core Patch
@workflow/web-shared Patch
@workflow/web Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
example-nextjs-workflow-turbopack Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
example-nextjs-workflow-webpack Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
example-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-astro-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-express-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-fastify-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-hono-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-nestjs-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-nitro-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-nuxt-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-python-workflow Error Error v0 Nov 17, 2026 5:56pm UTC
workbench-sveltekit-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-tanstack-start-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workbench-vite-workflow Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workflow-docs Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workflow-swc-playground Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workflow-tarballs Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC
workflow-web Ready Ready Preview, v0 Nov 17, 2026 5:56pm UTC

@TooTallNate
TooTallNate enabled auto-merge (squash) November 17, 2026 18:24
@github-actions

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

🧪 E2E Test Results

❌ Some tests failed

Summary

Passed Failed Skipped Total
✅ ▲ Vercel Production 1110 0 78 1188
✅ 💻 Local Development 1210 0 86 1296
✅ 📦 Local Production 1210 0 86 1296
✅ 🐘 Local Postgres 1210 0 86 1296
✅ 🪟 Windows 108 0 0 108
❌ 🌍 Community Worlds 84 106 9 199
✅ 📋 Other 612 0 36 648
Total 5544 106 381 6031

❌ Failed Tests

🌍 Community Worlds (106 failed)

redis (20 failed):

  • hookWorkflow is not resumable via public webhook endpoint | wrun_01M7NC6C4JTJJD41G118EQ8J20
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01M7NC6QJRYAWVGSGWZ89KMNNE
  • sleepingWorkflow | wrun_01M7NC7RFEFYFGV87GMGRBFHWB
  • outputStreamWorkflow negative startIndex (reads from end)
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns correct index after stream completes
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns -1 before any chunks are written
  • outputStreamWorkflow - getTailIndex and getStreamChunks getStreamChunks returns same content as reading the stream
  • error handling serialization failures step-argument serialization failure is catchable in workflow code
  • error handling serialization failures uncaught step-argument serialization failure fails the run as USER_ERROR without redelivery retries
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01M7NCG174Y4A7MR7J730Q6HKE
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01M7NCGDZ3SY5TQVYMQ0J497YX
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01M7NCGR8HHYKG9MEJHBT7PFW1
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01M7NCH6K0H20SSJ8ZT59TND85
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01M7NCJ253J7YEK3JF6NGRM9ZT
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01M7NCJ6WYECKJ2A6ESMFP5PFE
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01M7NCJD17XMS0460W4N5NAGV1
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01M7NCJJG3GAEJ5CH3YGSRKE2W
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01M7NCJVY2V3A41A3JGBHJ3EHY
  • pages router sleepingWorkflow via pages router
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01M7NCS2805A0QYXSEC7XDD0KM

turso (86 failed):

  • addTenWorkflow | wrun_01M7NC55AA7G0FEMM1K2WP61R2
  • addTenWorkflow | wrun_01M7NC55AA7G0FEMM1K2WP61R2
  • deploymentId: 'latest' is a no-op in non-Vercel worlds
  • wellKnownAgentWorkflow (.well-known/agent) | wrun_01M7NC5R27ARKK72ZYMFR6AZP4
  • should work with react rendering in step
  • promiseAllWorkflow | wrun_01M7NC5DE680878YEN5B2R3A2S
  • promiseRaceWorkflow | wrun_01M7NC5J3E1P910ZW39P21WH3E
  • promiseAnyWorkflow | wrun_01M7NC5MK907GMVGCSYCDQMY4Q
  • importedStepOnlyWorkflow | wrun_01M7NC62EYWVZDCE9AMASDQYEY
  • readableStreamWorkflow | wrun_01M7NC5R0N4JAKFCPD6EGV85JB
  • hookWorkflow | wrun_01M7NC64PQAZBBA1MNJ76K4TRR
  • hookWorkflow is not resumable via public webhook endpoint | wrun_01M7NC6C4JTJJD41G118EQ8J20
  • webhookWorkflow | wrun_01M7NC6HH3F3E1QH82E4RDDNS1
  • parallelStepsThenWebhookWorkflow - no hook_conflict from same-tick replay race | wrun_01M7NC6QJRYAWVGSGWZ89KMNNE
  • sleepingWorkflow | wrun_01M7NC7RFEFYFGV87GMGRBFHWB
  • parallelSleepWorkflow | wrun_01M7NC88C503N5X7E166RW9Z3G
  • sleepWinsRaceWorkflow | wrun_01M7NC8BV1PZT8GY4V8547JMZE
  • stepWinsRaceWorkflow | wrun_01M7NC8FD6CDVZ80KR09AN30XD
  • nullByteWorkflow | wrun_01M7NC8JTEPYK4JDDF8B9ZTTDR
  • workflowAndStepMetadataWorkflow | wrun_01M7NC8N6QM6EFEMCZFNA9QE3G
  • outputStreamWorkflow no startIndex (reads all chunks)
  • outputStreamWorkflow positive startIndex (skips first chunk)
  • outputStreamWorkflow negative startIndex (reads from end)
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns correct index after stream completes
  • outputStreamWorkflow - getTailIndex and getStreamChunks getTailIndex returns -1 before any chunks are written
  • outputStreamWorkflow - getTailIndex and getStreamChunks getStreamChunks returns same content as reading the stream
  • outputStreamInsideStepWorkflow - getWritable() called inside step functions | wrun_01M7NCB11FG9P5QR8P9DYK1C27
  • writableForwardedFromWorkflowWorkflow | wrun_01M7NCBE71WWMGRACGX08GBR5X
  • writableForwardedFromStepWorkflow | wrun_01M7NCBHHJP6AHTNRMGEG3G0YK
  • fetchWorkflow | wrun_01M7NCBMJ0J50MGG5C01KSDHGZ
  • promiseRaceStressTestWorkflow | wrun_01M7NCBQZ6109ZGYZVP8HKYJ33
  • error handling error propagation workflow errors nested function calls preserve message and stack trace
  • error handling error propagation workflow errors cross-file imports preserve message and stack trace
  • error handling error propagation step errors basic step error preserves message and stack trace
  • error handling error propagation step errors cross-file step error preserves message and function names in stack
  • error handling retry behavior regular Error retries until success
  • error handling retry behavior FatalError fails immediately without retries
  • error handling retry behavior RetryableError respects custom retryAfter delay
  • error handling retry behavior maxRetries=0 disables retries
  • error handling catchability FatalError can be caught and detected with FatalError.is()
  • error handling serialization failures step-argument serialization failure is catchable in workflow code
  • error handling serialization failures uncaught step-argument serialization failure fails the run as USER_ERROR without redelivery retries
  • error handling not registered WorkflowNotRegisteredError fails the run when workflow does not exist
  • error handling not registered StepNotRegisteredError fails the step but workflow can catch it
  • error handling not registered StepNotRegisteredError fails the run when not caught in workflow
  • hookCleanupTestWorkflow - hook token reuse after workflow completion | wrun_01M7NCFMRHW94GXTGMQXF8SD2G
  • concurrent hook token conflict - two workflows cannot use the same hook token simultaneously | wrun_01M7NCG174Y4A7MR7J730Q6HKE
  • hookGetConflictWorkflow - awaiting hook.getConflict() registers hook without payload | wrun_01M7NCGDZ3SY5TQVYMQ0J497YX
  • 'hookGetConflictWithPriorStepWorkflow' - hook.getConflict() does not block step execution | wrun_01M7NCGGHY30TPQ6ZGJ3W6CJ1K
  • 'hookGetConflictWithParallelStepWorkfl…' - hook.getConflict() does not block step execution | wrun_01M7NCGNQN0JVKXDFS2WEGFRAX
  • hookGetConflictThenStepParallelWorkflow - hook.getConflict() continuation step runs alongside other steps | wrun_01M7NCGR8HHYKG9MEJHBT7PFW1
  • hookGetConflictWorkflow - hook.getConflict() resolves with the conflicting run when token is already registered | wrun_01M7NCH6K0H20SSJ8ZT59TND85
  • hookClaimOnlyMutexWorkflow - hook works as a pure run mutex without payload data | wrun_01M7NCJ253J7YEK3JF6NGRM9ZT
  • hookAdoptOwnerResultWorkflow - duplicate adopts the owner result via conflict.returnValue | wrun_01M7NCJ6WYECKJ2A6ESMFP5PFE
  • hookSignalOwnerWorkflow - duplicate forwards its payload to the owner via resumeHook | wrun_01M7NCJD17XMS0460W4N5NAGV1
  • hookSupersedeOwnerWorkflow - duplicate cancels the owner and claims the released token | wrun_01M7NCJJG3GAEJ5CH3YGSRKE2W
  • resume-or-start route pattern - resumeHook retried after start() reaches the new run | wrun_01M7NCJVY2V3A41A3JGBHJ3EHY
  • hookDisposeTestWorkflow - hook token reuse after explicit disposal while workflow still running | wrun_01M7NCK38NSMGPFJWSCJ6HEY1H
  • stepFunctionPassingWorkflow - step function references can be passed as arguments (without closure vars) | wrun_01M7NCKK692YEHACV5NZYK2HJM
  • stepFunctionWithClosureWorkflow - step function with closure variables passed as argument | wrun_01M7NCKYN24CE5D8RKVQX4NT13
  • closureVariableWorkflow - nested step functions with closure variables | wrun_01M7NCM4EQ1PEKAPPM7WM4MW7E
  • spawnWorkflowFromStepWorkflow - spawning a child workflow using start() inside a step | wrun_01M7NCM6QQXHKJZ3TB8Y9ZVQRW
  • health check (queue-based) - workflow and step endpoints respond to health check messages
  • health check (CLI) - workflow health command reports healthy endpoints
  • pathsAliasWorkflow - TypeScript path aliases resolve correctly | wrun_01M7NCMQ2BE3YRJ49YAGNK8QJ4
  • Calculator.calculate - static workflow method using static step methods from another class | wrun_01M7NCMWV7SQDW6EYJWFY45MF7
  • AllInOneService.processNumber - static workflow method using sibling static step methods | wrun_01M7NCN3MKP2VS2J0EQKX62QFS
  • ChainableService.processWithThis - static step methods using this to reference the class | wrun_01M7NCNDXYMRQ84GA3JPMEEPAQ
  • thisSerializationWorkflow - step function invoked with .call() and .apply() | wrun_01M7NCNMTCHWV8C0TW3B7RE7HD
  • customSerializationWorkflow - custom class serialization with WORKFLOW_SERIALIZE/WORKFLOW_DESERIALIZE | wrun_01M7NCNVSS9XE3BW6E290V3JWH
  • instanceMethodStepWorkflow - instance methods with "use step" directive | wrun_01M7NCP2MVZ6Q3G7VQAXKRY23M
  • crossContextSerdeWorkflow - classes defined in step code are deserializable in workflow context | wrun_01M7NCPG9NTK7WC4YFJRZNT04J
  • importedSerdeKeyWorkflow - classes keyed by imported WORKFLOW_SERIALIZE symbols round-trip through steps | wrun_01M7NCPSJX7PC79R1Z058G9R83
  • stepFunctionAsStartArgWorkflow - step function reference passed as start() argument | wrun_01M7NCQ0P60RQXD8J2T7F5H6DP
  • cancelRun - cancelling a running workflow | wrun_01M7NCQ7W32Z1YPJN23N4QB9H1
  • cancelRun via CLI - cancelling a running workflow | wrun_01M7NCQD095406XBZ3SZ63QS7X
  • pages router addTenWorkflow via pages router
  • pages router promiseAllWorkflow via pages router
  • pages router sleepingWorkflow via pages router
  • hookWithSleepWorkflow - hook payloads delivered correctly with concurrent sleep | wrun_01M7NCQMP2TWZRER25FMCP7NMC
  • hookWithSleepFinalStepWorkflow - step only on final payload | wrun_01M7NCR12AN9RGHD1D8Z1K4BH0
  • sleepInLoopWorkflow - sleep inside loop with steps actually delays each iteration | wrun_01M7NCRA74FDXBWP65CXKV5MSA
  • sleepWithSequentialStepsWorkflow - sequential steps work with concurrent sleep (control) | wrun_01M7NCRP1YCPGF2YM7A462XAKR
  • importMetaUrlWorkflow - import.meta.url is available in step bundles | wrun_01M7NCRXAB9KGVCJK7ZVNETA76
  • metadataFromHelperWorkflow - getWorkflowMetadata/getStepMetadata work from module-level helper (#1577) | wrun_01M7NCRZSYNKZYH3DSM06MW7ZW
  • resilient start: addTenWorkflow completes when run_created returns 500 | wrun_01M7NCS2805A0QYXSEC7XDD0KM

Details by Category

✅ ▲ Vercel Production
App Passed Failed Skipped
✅ astro 100 0 8
✅ example 100 0 8
✅ express 100 0 8
✅ fastify 100 0 8
✅ hono 100 0 8
✅ nextjs-turbopack 105 0 3
✅ nextjs-webpack 105 0 3
✅ nitro 100 0 8
✅ nuxt 100 0 8
✅ sveltekit 100 0 8
✅ vite 100 0 8
✅ 💻 Local Development
App Passed Failed Skipped
✅ astro-stable 102 0 6
✅ express-stable 102 0 6
✅ fastify-stable 102 0 6
✅ hono-stable 102 0 6
✅ nextjs-turbopack-canary 89 0 19
✅ nextjs-turbopack-stable 108 0 0
✅ nextjs-webpack-canary 89 0 19
✅ nextjs-webpack-stable 108 0 0
✅ nitro-stable 102 0 6
✅ nuxt-stable 102 0 6
✅ sveltekit-stable 102 0 6
✅ vite-stable 102 0 6
✅ 📦 Local Production
App Passed Failed Skipped
✅ astro-stable 102 0 6
✅ express-stable 102 0 6
✅ fastify-stable 102 0 6
✅ hono-stable 102 0 6
✅ nextjs-turbopack-canary 89 0 19
✅ nextjs-turbopack-stable 108 0 0
✅ nextjs-webpack-canary 89 0 19
✅ nextjs-webpack-stable 108 0 0
✅ nitro-stable 102 0 6
✅ nuxt-stable 102 0 6
✅ sveltekit-stable 102 0 6
✅ vite-stable 102 0 6
✅ 🐘 Local Postgres
App Passed Failed Skipped
✅ astro-stable 102 0 6
✅ express-stable 102 0 6
✅ fastify-stable 102 0 6
✅ hono-stable 102 0 6
✅ nextjs-turbopack-canary 89 0 19
✅ nextjs-turbopack-stable 108 0 0
✅ nextjs-webpack-canary 89 0 19
✅ nextjs-webpack-stable 108 0 0
✅ nitro-stable 102 0 6
✅ nuxt-stable 102 0 6
✅ sveltekit-stable 102 0 6
✅ vite-stable 102 0 6
✅ 🪟 Windows
App Passed Failed Skipped
✅ nextjs-turbopack 108 0 0
❌ 🌍 Community Worlds
App Passed Failed Skipped
✅ mongodb-dev 4 0 3
✅ redis-dev 4 0 3
❌ redis 69 20 0
✅ turso-dev 4 0 3
❌ turso 3 86 0
✅ 📋 Other
App Passed Failed Skipped
✅ e2e-local-dev-nest-stable 102 0 6
✅ e2e-local-dev-tanstack-start-stable 102 0 6
✅ e2e-local-postgres-nest-stable 102 0 6
✅ e2e-local-postgres-tanstack-start-stable 102 0 6
✅ e2e-local-prod-nest-stable 102 0 6
✅ e2e-local-prod-tanstack-start-stable 102 0 6

📋 View full workflow run

@TooTallNate
TooTallNate merged commit b3eb7ae into stable Nov 17, 2026
95 of 99 checks passed
@TooTallNate
TooTallNate deleted the backport/pr-5503-to-stable branch November 17, 2026 18:38

This branch was successfully deployed

1 active deployment
Preview – workflow-docs — 37665b85 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant